package com.zzyy.study.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zzyy.study.po.AccountPO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;

public interface AccountMapper extends BaseMapper<AccountPO>
{
    /**
     * 收款方，增加账户余额
     *
     * @param accountId
     * @param price
     * @return
     */
    @Update("update t_account set balance = balance + #{price} where id = #{accountId} and #{price}>0")
    int balanceAdd(@Param("accountId") String accountId, @Param("price") BigDecimal price);

    /**
     * 支付方，减少账户余额
     * update t_account set balance = balance - ? where id = ? and balance - ? >=0 and ?>0
     * @param accountId
     * @param price
     * @return
     */
    @Update("update t_account set balance = balance - #{price} where id = #{accountId} and balance - #{price} >=0 and #{price}>0")
    int balanceSubtract(@Param("accountId") String accountId, @Param("price") BigDecimal price);
}
